<template>
  <div class="batch-apply">
    <el-form :model="form" label-width="100px" size="small">
      <!-- 关键字定位 -->
      <el-form-item label="关键字定位">
        <el-input 
          v-model="form.keyword" 
          placeholder="请输入关键字" 
          clearable
          @keyup.enter="handleOneAdd"
        >
          <template #append>
            <el-button @click="handleOneAdd">定位</el-button>
          </template>
        </el-input>
      </el-form-item>
      
      <!-- 显示签署落款 -->
      <el-form-item label="显示签署落款">
        <el-switch v-model="form.showSignature" />
      </el-form-item>
      
      <!-- 显示日期 -->
      <el-form-item label="显示日期">
        <el-switch v-model="form.showDate" />
      </el-form-item>
      
      <!-- 排列方向 -->
      <el-form-item label="排列方向">
        <el-radio-group v-model="form.direction">
          <el-radio :label="1">左右排列</el-radio>
          <el-radio :label="2">上下排列</el-radio>
        </el-radio-group>
      </el-form-item>
      
      <!-- 操作按钮 -->
      <el-form-item>
        <el-button type="primary" @click="handleOneAdd">批量添加</el-button>
        <el-button @click="handleClear">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { ref, defineComponent, reactive } from 'vue'

export default defineComponent({
  name: 'BatchApply',
  
  emits: ['one-add', 'clear'],
  
  setup(props, { emit }) {
    // 表单数据
    const form = reactive({
      keyword: '',
      showSignature: true,
      showDate: true,
      direction: 1 // 1: 左右排列, 2: 上下排列
    })
    
    /**
     * 处理批量添加
     */
    const handleOneAdd = () => {
      emit('one-add', form)
    }
    
    /**
     * 处理清空
     */
    const handleClear = () => {
      emit('clear')
    }
    
    return {
      form,
      handleOneAdd,
      handleClear
    }
  }
})
</script>

<style lang="scss" scoped>
.batch-apply {
  padding: 15px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  margin-bottom: 15px;
}
</style>